package cn.wolfcode.crm.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class CustomerTraceHistory {
    private Long id;

    //如果没有这个注解，会有400的问题（数据封装失败）
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date traceTime;

    private String traceDetails;

    private SystemDictionaryItem traceType;//跟进方式

    private Integer traceResult;

    private String remark;

    private Customer customer;//客户

    private Employee inputUser;

    private Date inputTime;

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("customerName", customer.getName());

        //fastjson在转换数据的时候，会自动将日期格式的数据转换成毫秒值
        //date转换成string
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");



        map.put("traceTime", sdf.format(traceTime));
        map.put("traceDetails", traceDetails);
        map.put("traceTypeId", traceType.getId());
        map.put("traceResult", traceResult);
        map.put("remark", remark);
        return JSON.toJSONString(map);
    }

}